#include <glib.h> 
static GMutex *give_me_next_number_mutex = NULL;

int calc_next_number(int number)
{
    return number+1;
}

  /* this function must be called before any call to give_me_next_number ()
     it must be called exactly once. */
  void init_give_me_next_number () 
{
    g_assert (give_me_next_number_mutex == NULL);
    give_me_next_number_mutex = g_mutex_new ();
}

  int give_me_next_number ()
{
    static int current_number = 0;
    int ret_val;

    g_mutex_lock (give_me_next_number_mutex);
    ret_val = current_number = calc_next_number (current_number); 
    g_mutex_unlock (give_me_next_number_mutex);
    return ret_val;
}


int main(int argc, char **argv)
{
    give_me_next_number();
    return 0;
}
